<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@page import="com.tcs.model.User"%>
<%@ page session="true"%>
<%
	User usuario = null;
	HttpSession sesionOk = request.getSession();
	if (sesionOk.getAttribute("usuario") == null) {
%>
<jsp:forward page="index.jsp">
	<jsp:param name="error" value="Es obligatorio identificarse" />
</jsp:forward>
<%
	} else {
		usuario = (User) sesionOk.getAttribute("usuario");
	}
%>
<%
	String name = usuario.getFirstName();
%>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<%@ include file="include-head.html"%>
</head>

<body>
	<!-- loading animation -->
	<div id="qLoverlay"></div>
	<div id="qLbar"></div>

	<jsp:include page="include-header.jsp" />

	<div id="wrapper">
		<!--Sidebar background-->
		<div id="sidebarbg"></div>


		<jsp:include page="include-sidebar.jsp" />

		<!--Body content-->
		<div id="content" class="clearfix">
			<div class="contentwrapper">
				<!--Content wrapper-->

				<div class="heading">
					<h3>Pedidos Abiertos</h3>
				</div>
				<!-- End .heading-->

				<!-- Build page from here: -->
				<div class="row-fluid">
					<div class="span12">



						<!-- COMIENZO LISTADO TABLA DE PEDIDOS -->

						<div class="box chart gradient">

							<div class="title">

								<h4>
									<a href="#" title="Descargar Reporte"
										onclick="generateexcel('Listado de Pedidos Abiertos', 'toXLS')"
										class="tip"><span class="icon16 icomoon-icon-download red"></span></a><span>Listado
										de Pedidos Abiertos</span>

								</h4>


							</div>
							<div class="content noPad clearfix">

								<c:if test="${!empty requisitions}">
									<table id="toXLS" cellpadding="0" cellspacing="0" border="0"
										class="responsive dynamicTable display table table-bordered"
										width="100%">
										<thead>
											<tr>
												<th>Nro de Pedido</th>
												<th>Fecha</th>
												<th>Detalle</th>
												<th>Modificar Pedido</th>

											</tr>
										</thead>
										<c:forEach items="${requisitions}" var="requisition">
											<tr class="odd gradeX">

												<td><a
													href="listReqDetailByReq.html?id=<c:out value="${requisition.requisitionId}"/>"
													title="Ver Detalle Pedido" class="tip"><c:out
															value="${requisition.requisitionId}" /></a></td>


												<td><c:out value="${requisition.requisitionDate}" /></td>
												

												<td>
													<div class="controls center">


														<a
															href="listReqDetailByReq.html?id=<c:out value="${requisition.requisitionId}"/>"
															title="Ver Detalle" class="tip"><span
															class="icon12 iconic-icon-read-more"></span></a>



													</div>
												</td>


												<td>
													<!-- Include the socket.io javascript on the client side -->
													<script src="http://localhost:8000/socket.io/socket.io.js"></script>
													<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>

													<script>
function llamarSocket(){


// Establish the connection with the server
var socket = io.connect('http://localhost:8000'); 



// Create a new socket connection
socket.on('connect', function() {

socket.emit('set nickname', 'cliente');

var txt =  '<%=name%>' +" cerro un nuevo pedido";
socket.emit('emit_msg', txt, function (data){
console.log ('Emit Broadcast msg', data);

});

});

}
</script> <script languaje="javascript">
function cierra(requisitionId){
alert('hola!') ;
window.location.href="closeRequisitionLink.html?id="+requisitionId;

}
</script>




													<div class="controls center">
														<a
															href="addReqDetail.html?id=<c:out value="${requisition.requisitionId}"/>"
															title="Agregar/Quitar Articulos" class="tip"><span
															class="icon12 icomoon-icon-puzzle"></span></a> 
															<a	href="closeRequisitionLink.html?id=<c:out value="${requisition.requisitionId}"/>"
															onclick="genera_ruta('http://localhost:8000/')"
															title="Cerrar / Despachar Pedido" class="tip"><span
															class="icon12 icomoon-icon-lightning"></span></a> <a href="#"
															onclick='llamarSocket(); cierra(<c:out value="${requisition.requisitionId}"/>)'
															title="Cerrar / Despachar Pedido" class="tip"><span
															class="icon12 icomoon-icon-lightning"></span></a> <a
															href="annulRequisition.html?id=<c:out value="${requisition.requisitionId}"/>"
															onclick="genera_ruta('http://localhost:8000/')"
															title="Anular" class="tip"><span
															class="icon12 icomoon-icon-remove"></span></a>






													</div>
												</td>



											</tr>
										</c:forEach>
									</table>
								</c:if>



							</div>

						</div>
						<!-- End .box -->

					</div>

					<c:if test="${param.state=='1'}">
						<c:url var="saveRequisitionUrl" value="/saveRequisition.html" />
						<form:form modelAttribute="requisition" method="POST"
							action="${saveRequisitionUrl}">

							<button type="submit" class="btn btn-primary">
								<span class="icon16 icomoon-icon-basket white"></span> Crear un
								nuevo Pedido
							</button>
						</form:form>

					</c:if>
					<c:url var="saveRequisitionUrl" value="/saveRequisition.html" />
					<form:form modelAttribute="requisition" method="POST"
						action="${saveRequisitionUrl}">

						<button type="submit" class="btn btn-primary">
							<span class="icon16 icomoon-icon-basket white"></span> Crear un
							nuevo Pedido
						</button>
					</form:form>
					<div class="marginB10"></div>

					<!-- End Span12 (ancho) -->
				</div>
				<!-- End .row-fluid -->
			</div>
			<!-- End contentwrapper -->
		</div>
		<!-- End #content -->
	</div>
	<!-- End #wrapper -->
	<script>




//	use_time_difference();
</script>



	<%@ include file="include-javascript.html"%>
</body>



</html>




